package com.wasion.core.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * 
 * @ClassName: ConfigReader
 * @Description: 配置文件加载器
 * @author 高意
 * @date Jun 7, 2013 10:15:03 AM
 * 
 */
public class ConfigReader {

	private Properties config = new Properties();

	/**
	 * @param propertiesFile
	 *            属性资源文件名称
	 */
	public ConfigReader(String propertiesFile) {

		try {

			InputStream in = ConfigReader.class.getClassLoader()
					.getResourceAsStream(propertiesFile);

			config.load(in);
		} catch (Exception e) {
			throw new RuntimeException("error, the properties file [ "
					+ propertiesFile + " ] does not exist");
		}

	}

	/**
	 * 
	 * @Title: getProperty
	 * @Description: 获取属性值
	 * @param key
	 *            配置属性key
	 * @return 配置属性value
	 * @throws
	 */
	public String getProperty(String key) {

		if (!config.containsKey(key)) {
			throw new RuntimeException("error, the key is missing");
		}

		return config.getProperty(key).trim().toString();
	}
}
